/*
 * Edited by: Dennis Feng
 * Created: 12 April 2012
 * 
 * Summary: Class that holds all important information for an individual task.
 */

package users;

/*
 * TaskData holds all the information for one task.
 */
public class TaskData {
	private String ownerName;
	private int taskID;
	private int groupID;
	private String title;
	private String taskBody;
	private String address;
	private double latitude;
	private double longitude;
	private boolean isCompleted;
	private boolean isNotificationOn;

	public TaskData() {
		super();
		ownerName = "";
		taskID = -1;
		groupID = -1;
		title = "";
		taskBody = "";
		address = "";
		latitude = 0.0;
		longitude = 0.0;
		isCompleted = false;
		isNotificationOn = true;
	}

	public TaskData(String input) {
		parseString(input);
	}

	public final String getOwner() {
		return ownerName;
	}

	public final Integer getTaskId() {
		return taskID;
	}

	public final Integer getGroupID() {
		return groupID;
	}

	public final String getTitle() {
		return title;
	}

	public final String getTaskBody() {
		return taskBody;
	}

	public final String getAddress() {
		return address;
	}

	public final double getLatitude() {
		return latitude;
	}

	public final double getLongitude() {
		return longitude;
	}

	public final boolean isTaskCompleted() {
		return isCompleted;
	}
	
	public final boolean isNotificationOn() {
		return isNotificationOn;
	}

	public void setOwner(String input) {
		ownerName = input;
	}
	public void setTaskId(int input) {
		taskID = input;
	}

	public void setGroupID(int input) {
		groupID = input;
	}

	public void setTitle(String input) {
		title = input;
	}

	public void setTaskBody(String input) {
		taskBody = input;
	}

	public void setAddress(String input) {
		address = input;
	}

	public void setLatitude(double input) {
		latitude = input;
	}

	public void setLongitude(double input) {
		longitude = input;
	}

	public void setIsTaskCompleted(boolean input) {
		isCompleted = input;
	}
	
	public void setIsNotificationOn(boolean input) {
		isNotificationOn = input;
	}

	// Used for converting string data into all the information of one task.
	public int parseString(String input) {
		String parts[] = input.split("<body>");
		taskBody = parts[1];
		
		String word[] = parts[0].split("\n");
		ownerName = word[0];
		taskID = Integer.valueOf(word[1]);
		groupID = Integer.valueOf(word[2]);
		title = word[3];
		address = word[4];
		latitude = Double.valueOf(word[5]);
		longitude = Double.valueOf(word[6]);
		
		if(word[7].contentEquals("true")) {
			isCompleted = true;
		} else {
			isCompleted = false;
		}
		
		if(word[8].contentEquals("true")) {
			isNotificationOn = true;
		} else {
			isNotificationOn = false;
		}

		return 1;
	}

	public String toString() {
		return ownerName + "\n" + taskID + "\n" + groupID + "\n" + title + "\n"
				+ address + "\n" + latitude + "\n" + longitude + "\n" + isCompleted + "\n"
				+ isNotificationOn + "\n" + "<body>" + taskBody + "<body><taskbreak>";
	}
	
	public final void displayTaskData() {
		System.out.println("Owner: " + ownerName);
		System.out.println("TaskID: " + taskID);
		System.out.println("GroupID: " + groupID);
		System.out.println("Title: " + title);
		System.out.println("Address: " + address);
		System.out.println("Latitude: " + latitude);
		System.out.println("Longitude: " + longitude);
		System.out.println("isCompleted: " + isCompleted);
		System.out.println("isNotificationOn: " + isNotificationOn);
		System.out.println("Body: " + taskBody);
	}
}

